/**
 * 
 */
package cn.gov.msa.controller;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.dom4j.DocumentException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.xmlpull.v1.XmlPullParserException;

import cn.gov.msa.util.PropertiesTools;
import cn.gov.msa.util.WebServiceTools;
import cn.msa.gov.model.UserDetail;
import net.sf.json.JSONObject;

/**   
* @Title: BusinessControll.java 
* @Package cn.gov.msa.controller 
* @Description: TODO(用一句话描述该文件做什么) 
* @author 何宇江  
* @date 2018年2月21日 上午11:34:09 
*/


@RestController
@RequestMapping(value = "/reserve", produces = "text/plain;charset=UTF-8")
public class ReserveController {

	private static String url  = PropertiesTools.readProperties("gahWS.url");
	private String methods = "stirnggetData";
	
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public String getList(@RequestBody JSONObject param, HttpSession session) throws Exception {
    			
		UserDetail userDetail = (UserDetail)session.getAttribute("user");
		String companyId = userDetail.getCompanyId();
		if(companyId == null || "".equals(companyId)){
			return "{\"total\":0,\"rows\":\"[]\"}";
		}
		// 查询当前登录用户所属公司的申报记录
		param.put("companyid", companyId);
        String[] parameter = new String[]{"DKU303", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
           	
        return result;  
    } 
	
	@RequestMapping(value = "/delete")
	public String delete(String RECORDID) throws Exception {
    			
    	JSONObject jsonResultData = new JSONObject();
    	jsonResultData.put("RECORDID",RECORDID);
//        String url = PropertiesTools.readProperties("gahWS.url");       
        String[] parameter = new String[]{"DKU303_1", jsonResultData.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
           	
        return result;  
    } 
	
	@RequestMapping(value = "/items", method = RequestMethod.POST)
	public String items(@RequestBody JSONObject param) throws Exception {
    			   	
//        String url = PropertiesTools.readProperties("gahWS.url");       
        String[] parameter = new String[]{"DKU303_2", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
           	
        return result;  
    } 
	
	@RequestMapping(value = "/insert" ,method = RequestMethod.POST)
	public String insert(@RequestBody JSONObject param) throws Exception {
    			   	
//        String url = PropertiesTools.readProperties("gahWS.url");       
        String[] parameter = new String[]{"DKU303_3", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
           	
        return result;  
    }
	
	
	@RequestMapping(value = "/getNum" ,method = RequestMethod.POST)
	public String getNum(@RequestBody JSONObject param) throws Exception {
//    	System.out.println("params:"+param);		   	
//        String url = PropertiesTools.readProperties("gahWS.url");       
        String[] parameter = new String[]{"DKU303_4", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
        return result;  
    }
	
	 
}
